#pragma once

#include <memory>
#include <string>
#include <boost/thread.hpp>

// Forward declaration
class CppSQLite3DB;

class CLogDatabase
{
public:
	virtual ~CLogDatabase() = default;
	
	virtual int setDatabaseFilePath(const std::string& dbPath);
	// Get the database connection
	virtual CppSQLite3DB* getDatabaseConnection() const;
	
	// Get the database file path
	virtual std::string getDatabasePath() const;

	virtual int closeDatabase();
	virtual int initDatabase();
	virtual int createNoniusTable();
	
	// Unified nonius cursor management method
	virtual int updateNoniusCursor(const std::string& tableName, int tableId, uint64_t lastTime);
	
	// Query and delete methods
	virtual int getNoniusCursor(const std::string& tableName, uint64_t& startTime, uint64_t& lastTime, int& tableId);
	virtual int deleteNoniusCursor(const std::string& tableName);
	
	virtual void lock();
	virtual void unlock();

private:
	// Internal cursor management methods
	virtual int insertNoniusCursor(const std::string& tableName, int tableId, uint64_t startTime, uint64_t lastTime);
	virtual int updateNoniusCursorInternal(const std::string& tableName, uint64_t lastTime);

private:
	std::string m_dbPath; // Path to the database file
	CppSQLite3DB* m_dbConnection = nullptr; // Pointer to the SQLite database connection
	boost::mutex m_mutex; // Mutex for thread safety
};

typedef std::shared_ptr<CLogDatabase> CLogDatabasePtr;